/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.peanut.devlibrary.camera;

import android.os.Environment;
import android.os.StatFs;

/**
 * A utility class to handle various kinds of menu operations.
 */
public class MenuHelper {

	public static final int NO_STORAGE_ERROR = -1;
	public static final int CANNOT_STAT_ERROR = -2;

	public static int calculatePicturesRemaining() {
		try {
			if (!ImageManager.hasStorage()) {
				return NO_STORAGE_ERROR;
			} else {
				String storageDirectory = Environment
						.getExternalStorageDirectory().toString();
				StatFs stat = new StatFs(storageDirectory);
				final int PICTURE_BYTES = 1500000;
				float remaining = ((float) stat.getAvailableBlocks() * (float) stat
						.getBlockSize()) / PICTURE_BYTES;
				return (int) remaining;
			}
		} catch (Exception ex) {
			// if we can't stat the filesystem then we don't know how many
			// pictures are remaining. it might be zero but just leave it
			// blank since we really don't know.

			return CANNOT_STAT_ERROR;
		}
	}
}
